diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-12-18 00:45:12 -0700 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-12-18 00:45:12 -0700 |
commit | cfa0ff5e6a45ce2d17fe18a09268acb2c0eb6724 (patch) | |
tree | 6f60b73f14a4b1270da784997dc882fabe8151ab | |
parent | 2abb355a18934d72006e2958cf79fae1b18868ca (diff) | |
download | stage-cfa0ff5e6a45ce2d17fe18a09268acb2c0eb6724.tar.gz stage-cfa0ff5e6a45ce2d17fe18a09268acb2c0eb6724.tar.bz2 stage-cfa0ff5e6a45ce2d17fe18a09268acb2c0eb6724.tar.xz stage-cfa0ff5e6a45ce2d17fe18a09268acb2c0eb6724.zip |
The basic structure is complete.
-rw-r--r-- | demo.stage | 23 | ||||
-rw-r--r-- | src/parser.l | 12 | ||||
-rw-r--r-- | src/parser.y | 44 |
3 files changed, 68 insertions, 11 deletions
@@ -32,7 +32,16 @@ game | |||
32 | 32 | ||
33 | situation <<main>> | 33 | situation <<main>> |
34 | { | 34 | { |
35 | player.inventory = []; | 35 | command: "there" hi |
36 | { | ||
37 | } | ||
38 | setup | ||
39 | { | ||
40 | player.inventory = []; | ||
41 | } | ||
42 | enter | ||
43 | { | ||
44 | } | ||
36 | } | 45 | } |
37 | 46 | ||
38 | function hello() | 47 | function hello() |
@@ -41,11 +50,17 @@ function hello() | |||
41 | 50 | ||
42 | situation <<start>> | 51 | situation <<start>> |
43 | { | 52 | { |
44 | display('''You are here, there is a wrench sitting on the table.'''); | 53 | enter |
45 | global.command("use", | 54 | { |
55 | display('''You are here, there is a wrench sitting on the table.'''); | ||
56 | test("use", bob ); | ||
57 | } | ||
46 | } | 58 | } |
47 | 59 | ||
48 | situation <<end>> | 60 | situation <<end>> |
49 | { | 61 | { |
50 | goto( <<start>> ); | 62 | enter |
63 | { | ||
64 | goto( <<start>> ); | ||
65 | } | ||
51 | } | 66 | } |
diff --git a/src/parser.l b/src/parser.l index cbf359c..841c5e6 100644 --- a/src/parser.l +++ b/src/parser.l | |||
@@ -18,7 +18,15 @@ | |||
18 | %x dqstr tdqstr tsqstr | 18 | %x dqstr tdqstr tsqstr |
19 | %% | 19 | %% |
20 | 20 | ||
21 | [-{}<>=+/*,();:.] { return yytext[0]; } | 21 | "<=" { return tokLtEq; } |
22 | ">=" { return tokGtEq; } | ||
23 | "==" { return tokCmp; } | ||
24 | "+=" { return tokPlusAssign; } | ||
25 | "-=" { return tokMinusAssign; } | ||
26 | "*=" { return tokTimesAssign; } | ||
27 | "/=" { return tokDivideAssign; } | ||
28 | |||
29 | [-{}<>=+/*,();:.[\]] { return yytext[0]; } | ||
22 | 30 | ||
23 | game { return tokGame; } | 31 | game { return tokGame; } |
24 | function { return tokFunction; } | 32 | function { return tokFunction; } |
@@ -34,6 +42,8 @@ else { return tokElse; } | |||
34 | command { return tokCommand; } | 42 | command { return tokCommand; } |
35 | goto { return tokGoto; } | 43 | goto { return tokGoto; } |
36 | not { return tokNot; } | 44 | not { return tokNot; } |
45 | setup { return tokSetup; } | ||
46 | enter { return tokEnter; } | ||
37 | 47 | ||
38 | true { yylval->bValue = true; return tokBool; } | 48 | true { yylval->bValue = true; return tokBool; } |
39 | false { yylval->bValue = false; return tokBool; } | 49 | false { yylval->bValue = false; return tokBool; } |
diff --git a/src/parser.y b/src/parser.y index e2f8b6d..95bd00d 100644 --- a/src/parser.y +++ b/src/parser.y | |||
@@ -37,6 +37,8 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, const char *error ) | |||
37 | %token tokGame | 37 | %token tokGame |
38 | %token tokFunction | 38 | %token tokFunction |
39 | %token tokSituation | 39 | %token tokSituation |
40 | %token tokSetup | ||
41 | %token tokEnter | ||
40 | %token tokWhile | 42 | %token tokWhile |
41 | %token tokFor | 43 | %token tokFor |
42 | %token tokEach | 44 | %token tokEach |
@@ -47,6 +49,13 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, const char *error ) | |||
47 | %token tokNot | 49 | %token tokNot |
48 | %token tokCommand | 50 | %token tokCommand |
49 | %token tokPlayer | 51 | %token tokPlayer |
52 | %token tokLtEq | ||
53 | %token tokGtEq | ||
54 | %token tokCmp | ||
55 | %token tokPlusAssign | ||
56 | %token tokMinusAssign | ||
57 | %token tokTimesAssign | ||
58 | %token tokDivideAssign | ||
50 | %token <sValue> tokSituationName | 59 | %token <sValue> tokSituationName |
51 | %token <sValue> tokIdent | 60 | %token <sValue> tokIdent |
52 | %token tokGoto | 61 | %token tokGoto |
@@ -60,7 +69,9 @@ void yyerror( YYLTYPE *llocp, yyscan_t yyscanner, const char *error ) | |||
60 | 69 | ||
61 | %token eos 0 "end of stream" | 70 | %token eos 0 "end of stream" |
62 | 71 | ||
63 | %right '=' | 72 | %right tokNot |
73 | %right '=' tokPlusAssign tokMinusAssign tokTimesAssign tokDivideAssign | ||
74 | %right tokLtEq tokGtEq tokCmp | ||
64 | %left tokIn | 75 | %left tokIn |
65 | %left '(' ')' '[' ']' | 76 | %left '(' ')' '[' ']' |
66 | %left '*' '/' | 77 | %left '*' '/' |
@@ -89,9 +100,21 @@ bodyDecl: | |||
89 | | bodyDecl function | 100 | | bodyDecl function |
90 | ; | 101 | ; |
91 | 102 | ||
92 | situation: tokSituation tokSituationName { printf("Read situtaion: %s\n", (*$2).getStr() ); } '{' cmpltExprList '}' | 103 | situation: tokSituation tokSituationName { printf("Read situtaion: %s\n", (*$2).getStr() ); } '{' situationMembers '}' |
93 | ; | 104 | ; |
94 | 105 | ||
106 | situationMembers: | ||
107 | | situationMembers situationModeFunc | ||
108 | | situationMembers commandDecl | ||
109 | ; | ||
110 | |||
111 | situationModeFunc: situationMode '{' cmpltExprList '}' | ||
112 | ; | ||
113 | |||
114 | situationMode: tokSetup | ||
115 | | tokEnter | ||
116 | ; | ||
117 | |||
95 | function: tokFunction tokIdent '(' ')' '{' '}' | 118 | function: tokFunction tokIdent '(' ')' '{' '}' |
96 | ; | 119 | ; |
97 | 120 | ||
@@ -109,15 +132,24 @@ ifnext: | |||
109 | | tokElse tokIf '{' cmpltExprList '}' ifnext | 132 | | tokElse tokIf '{' cmpltExprList '}' ifnext |
110 | ; | 133 | ; |
111 | 134 | ||
135 | varRef: tokIdent | ||
136 | | tokPlayer '.' tokIdent | ||
137 | | tokSituation '.' tokIdent | ||
138 | ; | ||
139 | |||
112 | expr: tokInt | 140 | expr: tokInt |
113 | | tokFloat | 141 | | tokFloat |
114 | | tokString | 142 | | tokString |
115 | | tokBool | 143 | | tokBool |
116 | | tokNull | 144 | | tokNull |
117 | | tokIdent | 145 | | tokIdent '(' listValues ')' |
146 | | varRef | ||
147 | | varRef '=' expr | ||
148 | | varRef tokPlusAssign expr | ||
149 | | varRef tokMinusAssign expr | ||
150 | | varRef tokTimesAssign expr | ||
151 | | varRef tokDivideAssign expr | ||
118 | | tokSituationName | 152 | | tokSituationName |
119 | | tokSituation '.' tokIdent | ||
120 | | tokPlayer '.' tokIdent | ||
121 | | expr '+' expr | 153 | | expr '+' expr |
122 | | expr '-' expr | 154 | | expr '-' expr |
123 | | expr '/' expr | 155 | | expr '/' expr |
@@ -129,7 +161,7 @@ expr: tokInt | |||
129 | | '[' listValues ']' | 161 | | '[' listValues ']' |
130 | | '{' '}' | 162 | | '{' '}' |
131 | | '{' dictValues '}' | 163 | | '{' dictValues '}' |
132 | /* | tokNot expr */ | 164 | | tokNot expr |
133 | ; | 165 | ; |
134 | 166 | ||
135 | listValues: expr | 167 | listValues: expr |